#ifndef _sbrush_sms_synthesizer_h_
#define _sbrush_sms_synthesizer_h_

#include "sbrush_sms.h"
#include "sbrush_audio_manager.h"
#include "sms.h"
#include "dag_threading.h"

namespace sbrush {
	
	class SynthNotInitialized : public SmsError {
	public:
		SynthNotInitialized();
		virtual ~SynthNotInitialized() throw();
	};
	
	class NoSmsFrame : public SmsError {
	public:
		NoSmsFrame();
		virtual ~NoSmsFrame() throw();
	};
	
	class SmsSynthesizer : public AudioSource, public Sms {
	public:
		SmsSynthesizer();
		virtual ~SmsSynthesizer() throw();
		void addAudio(float** buffer, size_t numChannels, size_t numFrames);
		void init(const SMS_Header& header,
				  int sampleRate);
		const SMS_Header& header() const;
		bool isReady() const;
		size_t samplesPerSmsFrame() const;
		void setFrame(const SMS_Data& synthData);
	private:
		size_t addAudioFromInternal(float** buffer, 
									size_t numChannels, 
									size_t numFrames, 
									size_t bufferOffset);
		SMS_SynthParams m_SynthParams;
		SMS_Header m_Header;
		const SMS_Data* m_CurrentFrame;
		bool m_Initialized;
		dag::Mutex m_AudioMutex;
		float* m_InternalBuffer;
		size_t m_InternalBufferSize;
		size_t m_SamplesInBuffer;
	};
}


#endif